Return to doc.sitecore.com

4.  Migrating Users Between Domains
Prev Next

In previous section the process of adding a new domain to the Sitecore has been described.

In this section we will describe a few ways of migrating data from one domain to another.


Case One
You need a new domain similar to the one you already have but without any Users/Roles.

Copy an existing database, give it a new name. Users and Roles may be removed manually.


Case Two
You want to split a domain in two or merge several domains.

In such case the Transfer option may be used. This option can be accessed either via the Control Panel

(Sitecore » Control Panel » Transfer Items to Another Database) or from the Content Editor Toolbar.

Create a database for the new domain, switch to the database which will be used as a source and use the transfer option.
Note: rights assignments for Users and Roles are not copied during the transfer process. Rights should be reassigned either manually or programmatically. You may use the code below to copy the rights:

private static void CopyRights(Domain from, Domain to, Item rootItem)
      {
        
if(rootItem != null)
         {
            
using(new SecurityDisabler())
            {
               ArrayList assignments
= new ArrayList();
              
for(int i = 0; i < rootItem.SecurityField.Assignments.Count; i++)
               {
                  
if(rootItem.SecurityField.Assignments[i].DomainName == from.Name)
                  {
                     assignments.Add(rootItem.SecurityField.Assignments[i]);
                  }
               }
              
foreach(SecurityAssignment assignment in assignments)
               {
                  rootItem.Editing.BeginEdit();
                  rootItem.SecurityField.SetRights(to, assignment.EntityID, rootItem.SecurityField.GetRights(from, assignment.EntityID));
                  rootItem.Editing.EndEdit();
               }
            }
            
if(rootItem.HasChildren)
            {
               ChildList children
= rootItem.Children;
              
for(int i = 0; i < children.Count; i++)
               {
                  CopyRights(from, to, children[i]);
               }
            }
         }
      }

Prev Next